home *** CD-ROM | disk | FTP | other *** search
/ ASME's Mechanical Engine…ing Toolkit 1997 December / ASME's Mechanical Engineering Toolkit 1997 December.iso / c_lang / varinc.lzh / README.DOC < prev    next >
Encoding:
Text File  |  1979-11-30  |  7.4 KB  |  170 lines

  1.                   COMPANION DISK TO VARIATIONS IN C
  2.  
  3.  
  4. This Companion Disk is for use in conjunction with the book
  5. "Variations in C", by Steve Schustack (Microsoft Press, 1985), to help
  6. you learn to program in the C language. To use the disk, you will need
  7. MS-DOS, version 2.0 or higher, and the Microsoft C Compiler, version
  8. 3.0 or higher.
  9.  
  10. ***Before you read any further, take a minute to make a backup copy of
  11. the disk, and store the original in a safe place.***
  12.  
  13. CONTENTS OF THE DISK:
  14. The Companion Disk contains all of the functions and header files that
  15. appear in "Variations in C", as well as selected illustrative code
  16. segments. All C code is in uncompiled source form, stored in separate
  17. ASCII text files, ready for you to edit and compile.
  18. There are four kinds of C code on the disk: an application, individual
  19. functions, header files, and code segments. Before we look at ideas
  20. about how you may use each of these, let's see where they can be
  21. found.
  22.  
  23. DIRECTORIES AND THEIR FILES:
  24. The organization of the Companion Disk parallels that of the book. The
  25. C source code and header files from each chapter are stored in a
  26. subdirectory named for the chapter--ch2, ch3, ..., ch21. (There are no
  27. directories for Chapters 1 and 9 because they contain no examples, nor
  28. for Chapter 11 because all of its examples can be found in Chapter
  29. 10.)
  30. Each complete order-entry function is stored in its own source file,
  31. with the same name as the function. For example, the function prompt()
  32. from Chapter 10 is found in subdirectory \ch10 in the file prompt.c.
  33. Some utility main() functions are also stored in ".c" files named for
  34. their intended uses. For instance, the line-numbering utility program
  35. from chapter 8 is in directory \ch8 in the file named listing.c, and
  36. the source-code reindenter is in \ch15\rein.c.
  37. Other functions and code segments are stored in files named for the
  38. page where they appear in the book. When there is more than one
  39. example on a page, the file name includes a letter indicating the
  40. code's position on that page. For instance, the single example on page
  41. 9 is stored in the file \ch2\page9.c, but the two segments listed on
  42. page 22 of Chapter 2 are stored in the directory \ch2 in the files
  43. page22a.c and page22b.c.
  44.  
  45. EXPERIMENTING WITH EXAMPLE PROGRAMS:
  46.  
  47. ***If you haven't already done so, be sure to make a backup copy of
  48. the Companion Disk and store it in a safe place before you begin
  49. working with the code.***
  50.  
  51. You will learn C more quickly if you experiment with the new concepts
  52. presented in the examples. For instance, let's suppose that you are
  53. reading the first program on page 22 of "Variations in C" and are
  54. curious about the effects of modifying it to input a short int and a
  55. double, rather than a long int and a double, as it does now. With the
  56. Companion Disk in drive A and your own C source data disk in drive B,
  57. you can copy the program like this:
  58.  
  59.      COPY A:\CH2\PAGE22A.C B:
  60.  
  61. (Although they are not needed in this case, some examples do require
  62. that the header files from Chapter 10 be #included, so copy them as
  63. well, using the syntax COPY A:\CH10\*.H B:)
  64.  
  65.  
  66.  
  67. Now you can edit the program and change some of the declarations,
  68. comments, and format specifiers, so that the program reads:
  69.  
  70. /* This program will input and output short and double data.        */
  71.  
  72. #include <stdio.h>                 /* We'll learn about this later. */
  73.  
  74. main()
  75.    {
  76.    short shrt;                /* Declare variables and their types. */
  77.    double dbl;
  78.  
  79.    printf("Enter short int and double: ");   /* Prompt for numbers. */
  80.    scanf("%hd %F", &shrt, &dbl);                  /* Input numbers. */
  81.  
  82.    printf("You entered %d %f.\n", shrt, dbl);   /* Display results. */
  83.    }
  84.  
  85. With these changes made, the program is ready for you to compile,
  86. link, and execute.
  87. Not all files on this disk are complete programs, however. Consider
  88. the second code segment on page 50 in Chapter 4 (\CH4\PAGE50B.C) that
  89. strips leading spaces from a string named "text". It lacks definition
  90. of a main() function--declarations, input of text to process, and
  91. output of results. But when you insert the code from page 50 into the
  92. framework shown below, it is ready for you to compile:
  93.  
  94. /* Framework for code on page 50 of Chapter 4 (\CH4\PAGE50B.C).    */
  95.    main()
  96.       {
  97.       short from_pos, to_pos, last_space;
  98.       char text[81];
  99.  
  100.       printf("\nEnter text: ");
  101.       gets(text);
  102.  
  103.  
  104.       /***  Insert segment from file \CH4\PAGE50B.C here.  ***/
  105.  
  106.  
  107.       printf("\ntext is now %s, len = %d\n", text, strlen(text));
  108.       }
  109.  
  110. BUILDING AND USING THE PROJECT UTILITY LIBRARY:
  111. The general nature of the project utility functions will make them
  112. useful tools in a variety of your own applications, if you take the
  113. time to make them readily accessible. Here's how.
  114. Use the MS-DOS LIB command to build a library holding these utility
  115. functions, AFTER you have compiled each of them to object form. First,
  116. request the interactive form of the LIB command by typing LIB. Then
  117. choose a name for your new library and enter it in response to the
  118. "Library name:" prompt. LIB will create the file for you. Finally, add
  119. your object files to the library file at the "Operations:" prompt, by
  120. typing a plus sign and file name (+ MATCH) for each file you want to
  121. include. From then on, you may call these utility functions from
  122. within your programs by specifying the name of your project utility
  123. library to the LINK command, along with the names of your own
  124. functions and the other libraries you use.
  125.  
  126. BUILDING THE ORDER-ENTRY PROGRAM:
  127. The Companion Disk contains the complete source code for the order-
  128. entry application program, as listed in Chapter 10. (Chapters 11
  129. through 13 describe these general-purpose and application-specific
  130. functions in detail.) You may use the order-entry program directly,
  131. applying it to taking orders for your own business, or you may choose
  132. to extend it first with new subsystems or additional capabilities.
  133.  
  134. To turn the existing source code into a working order-entry program,
  135. just compile and link all the functions from Chapter 10 (except those
  136. in the files stubs.c and page123.c), plus those listed in the table
  137. below (the working versions of the functions in stubs.c):
  138.  
  139.      Stub Function  File with Working Function
  140.      =============  ==========================
  141.      inv_find()     \ch19\inv_find.c
  142.      pw_find()      \ch17\pw_find.c
  143.      order_num()    \ch17\ordernum.c
  144.      logentry()     \ch17\logentry.c
  145.  
  146. If you have already built the project utility library, then you won't
  147. need to compile the project utility functions again now. Instead, just
  148. tell the linker to find them in the library you created earlier.
  149. To adapt the order-entry program to a completely different
  150. application, replace the main() function in ordentry.c and the middle-
  151. level functions in ordbuild.c with code that prompts for your own kind
  152. of data, rather than order data. Remember to replace the contents of
  153. the ordentry.h file with descriptions of the new data. The overall
  154. program structure may require little, if any, modification to handle a
  155. variety of applications.
  156.  
  157. QUESTIONS ABOUT THE DISK:
  158. Should you have any problems with your disk, please write to:
  159.  
  160. Microsoft Press
  161. Attn: Sales Division
  162. Box 97200
  163. 10700 Northup Way
  164. Bellevue, WA 98009
  165.  
  166. If you have any questions about the programs or code segments included
  167. on the Companion Disk, please write to:
  168.  
  169. Steve Schustack
  170. 968 Emerald Street, Suite A-116
  171. San Diego, CA  92109
  172.